package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

/**
 * Created by huanghaosheng on 2021/4/13 20:08
 * 背夹型号属性处理器
 */
public class JacketModelAttrHandler extends AbstractAttrHandler<KiteProdInst, AttrData> {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteProdInst inst, AttrData data) {
        KiteAttr mainProdModelAttr = null;
        String offerInstId = querySceneInstService.getSceneInst(data.getSceneInstId()).getRootInstId();
        List<KiteProdInst> kiteProdInstList = querySceneInstService
            .listProdInstsFromOfferInst(data.getCustId(), offerInstId);
        if (KiteListUtils.isNotEmpty(kiteProdInstList)) {
            mainProdModelAttr = kiteProdInstList.get(0).getAttr("200002772"); //主框架产品的型号
        }
        if (!KiteObjectUtils.isEmpty(mainProdModelAttr)) {
            if (!KiteStringUtils.isEqual("110006936", mainProdModelAttr.getValue())) { //型号
                attr.setIsEdit("F");
                super.set(attr, inst, mainProdModelAttr.getValue(), data);
            }
            else {
                attr.setIsEdit("T");
                super.set(attr, inst, "100007525", data);
            }
        }
    }
}
